package com.imooc.converter;

import com.imooc.dataobject.OrderMaster;
import com.imooc.dto.OrderDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Page;

import java.util.List;
import java.util.stream.Collectors;

/**
 * FileName: OrderMaster2OrderDTOConverter.java
 * Description: 订单转换工具类
 *
 * @author HuangRI(874668739 @ qq.com)
 * @version 1.0
 * @date 2020/12/18
 */
public final class OrderMaster2OrderDTOConverter {

    private OrderMaster2OrderDTOConverter() {}

    /**
     * OrderMaster转为OrderDTO
     * @param orderMaster OrderMaster
     * @return OrderDTO
     */
    public static OrderDTO convert(OrderMaster orderMaster) {
        OrderDTO orderDTO = new OrderDTO();
        BeanUtils.copyProperties(orderMaster, orderDTO);
        return orderDTO;
    }

    /**
     * OrderMaster List转为OrderDTO List
     * @param orderMasters OrderMaster List
     * @return OrderDTO List
     */
    public static List<OrderDTO> convert(List<OrderMaster> orderMasters) {
        return orderMasters.stream()
                .map(OrderMaster2OrderDTOConverter::convert)
                .collect(Collectors.toList());
    }

    /**
     * Page<OrderMaster>转换为Page<OrderDTO>
     * @param orderMasterPage Page<OrderMaster>
     * @return Page<OrderDTO>
     */
    public static Page<OrderDTO> convert(Page<OrderMaster> orderMasterPage) {
        return orderMasterPage.map(OrderMaster2OrderDTOConverter::convert);
    }
}
